<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<%String ctx = request.getContextPath();%>
<link href="<%=ctx%>/css/bootstrap.min.css"  rel="stylesheet">
<link href="<%=ctx%>/css/editormd.min.css"  rel="stylesheet">
<link href="<%=ctx%>/css/manage.css"  rel="stylesheet">
<script src="<%=ctx%>/js/jquery.min.js" type="text/javascript" ></script>
<script src="<%=ctx%>/js/editormd.min.js" type="text/javascript"></script>

<script>
	function AjaxLoad(uri) {
		let xmlHttp = new XMLHttpRequest();
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState === 4 && xmlHttp.status === 200) {
				$("#ajax-div").html(xmlHttp.responseText);
			}
		}
		xmlHttp.open("POST", uri,  true);
		xmlHttp.send();
	}

	function finishExam() {
		if(confirm("交卷后不可作答，确认交卷?") === true) {
			$.ajax(
					{
						type:"GET",
						url: '<%=ctx%>/u/ctrl?act=finishExam',
						data: {},
						success: function(data, status) {;
							if(data.length > 0) {
								alert(data);
							}
							AjaxLoad('<%=ctx%>/u/ctrl?act=getActiveExam');
						},
						error: function(req, status, msg) {
							alert(msg);
						}
					}
			)
		}
	}

</script>

<title>用户后台</title>
</head>
<body>
	<div id="left-nav" class="open">
		<div class="author-nav"> <img src="../img/user-logo.png"/> <h4>${name}</h4><h4>${number}</h4></div>
		<div class="main-nav">
			<ul> 
				<a onclick="AjaxLoad('<%=ctx%>/u/ctrl?act=getActiveExam')"> 
					<li>考试</li> 
				</a>
			</ul>
			<ul> 
				<a onclick="AjaxLoad('<%=ctx%>/u/ctrl?act=doExam')"> 
					<li>答题</li> 
				</a>
			</ul>
			<ul>
				<a onclick="finishExam()">
				<li>交卷</li>
				</a>
			</ul>
			<ul> 
				<a href="<%=ctx%>/servlet/LogoutServlet"> 
					<li>退出</li> 
				</a>
			</ul>
		</div>
	</div>

	<div id="ajax-div"/>
	
</body>
</html>